<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="销售单号" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入销售单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="ownerName">
        <el-input
          v-model="queryParams.ownerName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="ownerPhone">
        <el-input
          v-model="queryParams.ownerPhone"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址" prop="ownerAddress">
        <el-input
          v-model="queryParams.ownerAddress"
          placeholder="请输入地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产批次" prop="produceBatch">
        <el-input
          v-model="queryParams.produceBatch"
          placeholder="请输入生产批次"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="制作日期" prop="makeDate">
        <el-date-picker clearable
          v-model="queryParams.makeDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择制作日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="防伪编号" prop="antiCounterfeitingNumber">
        <el-input
          v-model="queryParams.antiCounterfeitingNumber"
          placeholder="请输入防伪编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="型号等级" prop="cueLevel">
        <el-input
          v-model="queryParams.cueLevel"
          placeholder="请输入型号等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="杆身材质" prop="cueMaterial">
        <el-input
          v-model="queryParams.cueMaterial"
          placeholder="请输入杆身材质"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="插花材质" prop="cueFlowerMaterial">
        <el-input
          v-model="queryParams.cueFlowerMaterial"
          placeholder="请输入插花材质"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['cue:cueInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['cue:cueInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['cue:cueInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['cue:cueInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="cueInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />


      <el-table-column label="销售信息" align="center" width="250" >
        <template #default="scope">
          <div>销售单号: {{ scope.row.orderId }}</div>
          <div>销售日期: {{ parseTime(scope.row.orderDate, '{y}-{m}-{d}') }}</div>
        </template>
      </el-table-column>

      <!-- <el-table-column label="销售单号" align="center" prop="orderId" />
      <el-table-column label="销售日期" align="center" prop="orderDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->

      <el-table-column label="客户信息" align="center" width="250" >
        <template #default="scope">
          <div>姓名: {{ scope.row.ownerName }}</div>
          <div>联系电话: {{ scope.row.ownerPhone }}</div>
          <div>地址: {{ scope.row.ownerAddress }}</div>
          <div>拥有时间: {{ parseTime(scope.row.ownerDate, '{y}-{m}-{d}') }}</div>

        </template>
      </el-table-column>

      <!-- <el-table-column label="姓名" align="center" prop="ownerName" />
      <el-table-column label="联系电话" align="center" prop="ownerPhone" />
      <el-table-column label="地址" align="center" prop="ownerAddress" /> -->
      <!-- <el-table-column label="拥有时间" align="center" prop="ownerDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ownerDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->

      <el-table-column label="生产信息" align="center" width="250" >
        <template #default="scope">
          <div>生产批次: {{ scope.row.produceBatch }}</div>
          <div>制作日期: {{ parseTime(scope.row.makeDate, '{y}-{m}-{d}') }}</div>
        </template>
      </el-table-column>

      <!-- <el-table-column label="生产批次" align="center" prop="produceBatch" />
      <el-table-column label="制作日期" align="center" prop="makeDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.makeDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="防伪编号" align="center" prop="antiCounterfeitingNumber" />
      <el-table-column label="型号等级" align="center" prop="cueLevel" />


      <el-table-column label="材质" align="center" width="250" >
        <template #default="scope">
          <div>杆身材质: {{ scope.row.cueMaterial }}</div>
          <div>插花材质: {{ scope.row.cueFlowerMaterial }}</div>
        </template>
      </el-table-column>

      <!-- <el-table-column label="杆身材质" align="center" prop="cueMaterial" />
      <el-table-column label="插花材质" align="center" prop="cueFlowerMaterial" /> -->

      <el-table-column label="参数" align="center" width="250" >
        <template #default="scope">
          <div>皮头: {{ scope.row.cueHead }}</div>
          <div>重量: {{ scope.row.cueWeight }}</div>
          <div>长度: {{ scope.row.cueLength }}</div>
          <div>握把: {{scope.row.cueGrip}}</div>
          <div>重心: {{scope.row.cueBarycenter}}</div>


        </template>
      </el-table-column>

      <!-- <el-table-column label="杆头直径" align="center" prop="cueHead" />
      <el-table-column label="球杆重量" align="center" prop="cueWeight" />
      <el-table-column label="球杆长度" align="center" prop="cueLength" />
      <el-table-column label="球杆握把" align="center" prop="cueGrip" />
      <el-table-column label="球杆重心" align="center" prop="cueBarycenter" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['cue:cueInfo:edit']"
          >修改</el-button>

          <el-button
            size="mini"
            type="text"
            @click="handlePreview(scope.row)"
          >预览</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['cue:cueInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改球杆信息管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="销售单号" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入销售单号" />
        </el-form-item>
        <el-form-item label="销售日期" prop="orderDate">
          <el-date-picker clearable
            v-model="form.orderDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择销售日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="姓名" prop="ownerName">
          <el-input v-model="form.ownerName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="联系电话" prop="ownerPhone">
          <el-input v-model="form.ownerPhone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="地址" prop="ownerAddress">
          <el-input v-model="form.ownerAddress" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="拥有时间" prop="ownerDate">
          <el-date-picker clearable
            v-model="form.ownerDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择拥有时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="生产批次" prop="produceBatch">
          <el-input v-model="form.produceBatch" placeholder="请输入生产批次" />
        </el-form-item>
        <el-form-item label="制作日期" prop="makeDate">
          <el-date-picker clearable
            v-model="form.makeDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择制作日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="防伪编号" prop="antiCounterfeitingNumber">
          <el-input v-model="form.antiCounterfeitingNumber" placeholder="请输入防伪编号" />
        </el-form-item>
        <el-form-item label="铭牌编号" prop="nameplateNumber">
          <el-input v-model="form.nameplateNumber" placeholder="请输入铭牌编号" />
        </el-form-item>
        <el-form-item label="型号等级" prop="cueLevel">
          <el-input v-model="form.cueLevel" placeholder="请输入型号等级" />
        </el-form-item>
        <el-form-item label="杆身材质" prop="cueMaterial">
          <el-radio-group v-model="form.cueMaterial">
            <el-radio v-for="dict in dict.type.cue_material" :key="dict.value" :label="dict.value">{{
              dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- <el-form-item label="杆身材质" prop="cueMaterial">
          <el-input v-model="form.cueMaterial" placeholder="请输入杆身材质" />
        </el-form-item> -->
        <el-form-item label="插花材质" prop="cueFlowerMaterial">
          <el-radio-group v-model="form.cueFlowerMaterial">
            <el-radio v-for="dict in dict.type.cue_flower_material" :key="dict.value" :label="dict.value">{{
              dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- <el-form-item label="插花材质" prop="cueFlowerMaterial">
          <el-input v-model="form.cueFlowerMaterial" placeholder="请输入插花材质" />
        </el-form-item> -->
        <el-form-item label="杆头直径" prop="cueHead">
          <el-input v-model="form.cueHead" placeholder="请输入杆头直径" />
        </el-form-item>
        <el-form-item label="球杆重量" prop="cueWeight">
          <el-input v-model="form.cueWeight" placeholder="请输入球杆重量" />
        </el-form-item>
        <el-form-item label="球杆长度" prop="cueLength">
          <el-input v-model="form.cueLength" placeholder="请输入球杆长度" />
        </el-form-item>
        <el-form-item label="球杆握把" prop="cueGrip">
          <el-input v-model="form.cueGrip" placeholder="请输入球杆握把" />
        </el-form-item>
        <el-form-item label="球杆重心" prop="cueBarycenter">
          <el-input v-model="form.cueBarycenter" placeholder="请输入球杆重心" />
        </el-form-item>
        <el-form-item label="轮播图" prop="albumPics">
          <oss-image-upload v-model="albumPics" :limit="5"></oss-image-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCueInfo, getCueInfo, delCueInfo, addCueInfo, updateCueInfo } from "@/api/cue/cueInfo";

export default {
  name: "CueInfo",
  dicts: ['cue_material', 'cue_flower_material'],

  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 球杆信息管理表格数据
      cueInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 球杆重心时间范围
      daterangeOwnerDate: [],

      albumPics:null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        ownerName: null,
        ownerPhone: null,
        ownerAddress: null,
        produceBatch: null,
        makeDate: null,
        antiCounterfeitingNumber: null,
        cueLevel: null,
        cueMaterial: null,
        cueFlowerMaterial: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderId: [
          { required: true, message: "销售单号不能为空", trigger: "blur" }
        ],
        orderDate: [
          { required: true, message: "销售日期不能为空", trigger: "blur" }
        ],
        ownerName: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        ownerPhone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
        ownerAddress: [
          { required: true, message: "地址不能为空", trigger: "blur" }
        ],
        ownerDate: [
          { required: true, message: "拥有时间不能为空", trigger: "blur" }
        ],
        produceBatch: [
          { required: true, message: "生产批次不能为空", trigger: "blur" }
        ],
        makeDate: [
          { required: true, message: "制作日期不能为空", trigger: "blur" }
        ],
        antiCounterfeitingNumber: [
          { required: true, message: "防伪编号不能为空", trigger: "blur" }
        ],
        
        // nameplateNumber: [
        //   { required: true, message: "铭牌编号不能为空", trigger: "blur" }
        // ],
        cueLevel: [
          { required: true, message: "型号等级不能为空", trigger: "blur" }
        ],
        cueMaterial: [
          { required: true, message: "杆身材质不能为空", trigger: "blur" }
        ],
        cueFlowerMaterial: [
          { required: true, message: "插花材质不能为空", trigger: "blur" }
        ],
        cueHead: [
          { required: true, message: "杆头直径不能为空", trigger: "blur" }
        ],
        cueWeight: [
          { required: true, message: "球杆重量不能为空", trigger: "blur" }
        ],
        cueLength: [
          { required: true, message: "球杆长度不能为空", trigger: "blur" }
        ],
        cueGrip: [
          { required: true, message: "球杆握把不能为空", trigger: "blur" }
        ],
        cueBarycenter: [
          { required: true, message: "球杆重心不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询球杆信息管理列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeOwnerDate && '' != this.daterangeOwnerDate) {
        this.queryParams.params["beginOwnerDate"] = this.daterangeOwnerDate[0];
        this.queryParams.params["endOwnerDate"] = this.daterangeOwnerDate[1];
      }
      listCueInfo(this.queryParams).then(response => {
        this.cueInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderId: null,
        orderDate: null,
        ownerName: null,
        ownerPhone: null,
        ownerAddress: null,
        ownerDate: null,
        produceBatch: null,
        makeDate: null,
        antiCounterfeitingNumber: null,
        nameplateNumber: null,

        cueLevel: null,
        cueMaterial: null,
        cueFlowerMaterial: null,
        cueHead: null,
        cueWeight: null,
        cueLength: null,
        cueGrip: null,
        cueBarycenter: null,
        cuePicList:null,
        updateTime: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeOwnerDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加球杆信息管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCueInfo(id).then(response => {
        this.form = response.data;
        if (this.form.cuePicList) {
          this.albumPics = this.form.cuePicList.split(',')
        }
        this.open = true;
        this.title = "修改球杆信息管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if(this.albumPics){
            this.form.cuePicList = this.albumPics.toString()
          }
          if (this.form.id != null) {
            updateCueInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCueInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除球杆信息管理编号为"' + ids + '"的数据项？').then(function() {
        return delCueInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },


        /** 预览 */
    handlePreview(row) {

      //this.$router.push({ path: '/cueAntiCounterfeiting', query: { antiCounterfeitingNumber: this.antiCounterfeitingNumber } })

      const routeUrl = this.$router.resolve({ path: '/cueAntiCounterfeiting', query: { antiCounterfeitingNumber: row.antiCounterfeitingNumber } }).href;
    window.open(routeUrl, '_blank');

    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('cue/cueInfo/export', {
        ...this.queryParams
      }, `cueInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
